package com.etc.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.Doctorlogin;
import com.etc.entity.Patientlogin;
import com.etc.service.DoctorloginService;
import com.etc.service.PatientLoginService;
import com.etc.util.MD5Util;
/**
 * 前台登录控制器
 * @author Administrator
 *
 */
@Controller
public class PatientLoginController {
	//病人
	@Autowired
	private PatientLoginService patientloginService;
	//医生
	@Autowired
	private DoctorloginService doctorloginService;
	/*@ResponseBody 
    @RequestMapping(value = "/checkPhone", produces = "application/json")
    public boolean  checkPhone(Model model,String phone) {
        AccountEntity entity = accountInterface.accountInfoByPhone(phone);
        if(entity==null){
           return false;
        }
        return true;
    }*/

	/**
	 * 病人登录
	 * @param patientloginid  用户账号
	 * @param userpwd   用户密码
	 * @param request    
	 * @param userType   用户类型   ：医生，病人
	 * @return
	 */
	@RequestMapping(value="getUserlogin",method=RequestMethod.GET)
	@ResponseBody
	public String getUserlogin(String userloginid,String userpwd ,HttpServletRequest request,String userType) {
		if ("pat".equals(userType)) {//类型为病人时
			Patientlogin patientlogin= patientloginService.getPatientLoginbyId(userloginid, MD5Util.getEncodeByMd5(userpwd));		
			if( patientlogin!=null) {
		    request.getSession().setAttribute("patientlogin", patientlogin);
			return "success/patient";
			}
			return "false";
		} else {//类型为医生
			Doctorlogin doctorlogin= doctorloginService.selectByPrimaryKey(Integer.valueOf(userloginid), userpwd);		
			if( doctorlogin!=null) {
		    request.getSession().setAttribute("doctorlogin", doctorlogin);
			return "success/doctor"+doctorlogin.getDoctorid();
			}
			return "false";
		}
		
	}
}


